package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.AlarmDataEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.AlarmDataEntityMapper;
import com.hzhr.iot.device.entity.AlarmDataEntity;
import com.hzhr.iot.device.entity.ext.AlarmDataEntityExt;
import com.hzhr.iot.device.queryModel.custom.AlarmDataCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AlarmDataDao {
    @Autowired
    AlarmDataEntityMapper alarmDataEntityMapper;
    @Autowired
    AlarmDataEntityCustomMapper alarmDataEntityCustomMapper;

    public int insert(AlarmDataEntity record) {
        if (record == null) return 0;
        int changeCount = alarmDataEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = alarmDataEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(AlarmDataEntity record) {
        if (record == null) return 0;
        int changeCount = alarmDataEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = alarmDataEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public AlarmDataEntity selectEntity(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<AlarmDataEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<AlarmDataEntity> selectEntityList(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<AlarmDataEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<AlarmDataEntity> entityList = new ArrayList<>();
        for (AlarmDataEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public AlarmDataEntityExt selectExt(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<AlarmDataEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<AlarmDataEntityExt> selectExtList(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<AlarmDataEntityExt> extList = alarmDataEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(AlarmDataCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = alarmDataEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
